package com.example;

import org.apache.http.auth.AuthScope;
import org.apache.http.auth.UsernamePasswordCredentials;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.BasicCredentialsProvider;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;

public class ClientAuthentication {

    public static void main(String[] args) {
        final BasicCredentialsProvider credentialsProvider = new BasicCredentialsProvider();
        credentialsProvider.setCredentials(
                new AuthScope("httpbin.org",80),
                new UsernamePasswordCredentials("user","pwd"));
        try(final CloseableHttpClient httpClient = HttpClients.custom()
                .setDefaultCredentialsProvider(credentialsProvider).build()){

            final HttpGet httpGet = new HttpGet("http://httpbin.org/basic-auth/user/passwd");
            final CloseableHttpResponse response = httpClient.execute(httpGet);
        }catch (Exception e){
            e.printStackTrace();
        }
    }
}
